package logic;

import network.message.MessageConstants;

/**
 * Created by IntelliJ IDEA.
 * User: grigory.rozhkov
 * Date: 12.09.12
 * Time: 0:34
 * To change this template use File | Settings | File Templates.
 */
public class ServerMessageHandler implements IMessageHandler {
    public String handleMessage(String message) {
        if (message == null) {
            return MessageConstants.STRANGE_SERVER_MESSAGE;
        }
        if ((message.length() >= MessageConstants.OK.length())
            && (MessageConstants.OK.equals(message.substring(0, MessageConstants.OK.length())))) {
            return MessageConstants.SUCCESS + message.substring(MessageConstants.OK.length(), message.length());
        }
        if ((message.length() >= MessageConstants.FAIL.length())
            && (MessageConstants.FAIL.equals(message.substring(0, MessageConstants.FAIL.length())))) {
            return MessageConstants.UNABLE_TO_PERFORM + message.substring(MessageConstants.FAIL.length(), message.length());
        }
        return MessageConstants.STRANGE_SERVER_MESSAGE;
    }
}
